import { Injectable }    from '@angular/core';
import { Headers, Http } from '@angular/http';

import 'rxjs/add/operator/toPromise';

@Injectable()
export class DataService{
	//private url = 'http://monitor.dcexploration.cn:5000/render/?target=DCEX-CA.BTC.sharelogger.hashratePool.Hashrate30m&format=json';
	private url = 'api/data';


	constructor(private http: Http) { }
	 
	getDatas(): Promise<any[]> {
	  return this.http.get(this.url)
	             .toPromise()
	             .then(response => {
	             	return response.json()
	             })
	             .catch(this.handleError);
	}
	private handleError(error: any): Promise<any> {
	  console.error('An error occurred', error); // for demo purposes only
	  return Promise.reject(error.message || error);
	}
}